package com.smartcar.client.controller;


import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.github.pagehelper.PageInfo;
import com.smartcar.client.config.AliPay;
import com.smartcar.client.config.AlipayConfig;
import com.smartcar.client.domin.*;
import com.smartcar.client.service.ClientService;
import com.smartcar.client.util.MapUtil;
import com.smartcar.client.util.PathUtil;
import com.smartcar.client.vo.AnnexVo;
import com.smartcar.client.vo.ConsumptionVo;
import com.smartcar.client.vo.RechargeVo;
import com.smartcar.common.domain.request.OrderRequest;
import com.smartcar.common.result.PageResult;
import com.smartcar.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.hutool.json.JSONObject;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author : 高文娜大美女
 * @className : ClientController
 * @description : 描述说明该类的功能
 * @createTime : 2023/10/15 10:25
 */
@RestController
@Log4j2
public class ClientController {
    @Autowired
   private ClientService clientService;
    @Autowired
    private MapUtil mapUtil;

    /**
     *用户详情
     */
    @PostMapping("/findByAnnex")
    public Result<Annex> findByAnnex(@RequestBody AnnexVo annexVo){
        Annex byAnnex = clientService.findByAnnex(annexVo);
        return Result.success(byAnnex);
    }
    /**
     * 消费记录
     */
    @PostMapping("/findByConsumption")
    public Result<PageResult<Consumption>> findByConsumption(@RequestBody ConsumptionVo consumptionVo){

        PageInfo<Consumption> info = clientService.findByConsumption(consumptionVo);
        return Result.success(PageResult.toPageResult(info.getTotal(), info.getList()));
    }
    /**
     * 充值记录
     */
    @PostMapping("/findByRecharge")
    public Result<PageResult<Recharge>> findByRecharge(@RequestBody RechargeVo rechargeVo){
        PageInfo<Recharge> info = clientService.findByRecharge(rechargeVo);
        return Result.success(PageResult.toPageResult(info.getTotal(), info.getList()));
    }
    /**
     * 会员信息
     */
    @GetMapping("/findByVipId/{userId}")
    public Result<Vip> findByVipId(@PathVariable String userId){
        Vip byVipId = clientService.findByVipId(userId);
        return Result.success(byVipId);
    }
    /**
     * 根据ip定位 获取经纬度
     */
    @PostMapping("/getDestination")
    public Result getDestination(@RequestParam("destination") String destination){
        Destination show = mapUtil.show(destination);
        return Result.success(show);
    }

    /**
     * 轨迹  线路
     * @param lineRequest
     * @return
     */
    @PostMapping("/queryLine")
    public Result<List<Map<String,Object>>> queryLine(@RequestBody LineRequest lineRequest){
        return Result.success(PathUtil.queryLine(lineRequest));
    }
    /**
     * 添加附件
     */
    @PostMapping("/insertAnnex")
    public Result insertAnnex(@RequestBody Annex annex){
        return Result.success(clientService.insertAnnex(annex));
    }
    /**
     * 修改附件
     * 充值复用
     */
    @PostMapping("/topUp")
    public Result topUp(@RequestBody Annex annex){
        return Result.success(clientService.topUp(annex));
    }
    /**
     * 添加会员
     */
    @PostMapping("/insertVip")
    public Result insertVip(@RequestBody Vip vip){
        return Result.success(clientService.insertVip(vip));
    }
    /**
     * 下单
     */
    @PostMapping("/insertOrder")
    public Result insertOrder(@RequestBody OrderRequest orderRequest){
     return Result.success(clientService.insertOrder(orderRequest));
    }
    /**
     * 根据经纬度获取地理位置
     */
    @PostMapping("/address")
    public Result<Destination> address(@RequestBody Destination destination){
        return Result.success(clientService.address(destination));
    }

}
